package com.myCode.classloader;

import java.lang.instrument.ClassDefinition;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import java.net.URLClassLoader;
import java.util.jar.JarFile;

/**
 * 查看类加载器实例
 *
 *
 */
public class ClassLoaderView {

    public static void main(String[] args) throws Exception {
        // // 加载核心类库的 BootStrap ClassLoader
        // System.out.println("核心类库加载器：" + ClassLoaderView.class.getClassLoader()
        //         .loadClass("java.lang.String").getClassLoader());
        // // 加载扩展库 Extension ClassLoader
        // System.out.println("扩展类库加载器：" + ClassLoaderView.class.getClassLoader()
        //         .loadClass("com.sun.nio.zipfs.ZipCoder").getClassLoader());
        //
        // // 加载应用程序的
        // System.out.println("应用程序库加载器：" + ClassLoaderView.class.getClassLoader());
        //
        // // 双亲委派模型
        // System.out.println("应用程序库加载器的父类的父类：" + ClassLoaderView.class.getClassLoader().getParent());
        // System.out.println("应用程序库加载器的父类的父类：" + ClassLoaderView.class.getClassLoader().getParent().getParent());
        //
        System.out.println("Hello World!");
        System.in.read();


        // URLClassLoader

        Instrumentation instrumentation = new Instrumentation() {
            @Override
            public void addTransformer(ClassFileTransformer transformer, boolean canRetransform) {

            }

            @Override
            public void addTransformer(ClassFileTransformer transformer) {

            }

            @Override
            public boolean removeTransformer(ClassFileTransformer transformer) {
                return false;
            }

            @Override
            public boolean isRetransformClassesSupported() {
                return false;
            }

            @Override
            public void retransformClasses(Class<?>... classes) throws UnmodifiableClassException {

            }

            @Override
            public boolean isRedefineClassesSupported() {
                return false;
            }

            @Override
            public void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException, UnmodifiableClassException {

            }

            @Override
            public boolean isModifiableClass(Class<?> theClass) {
                return false;
            }

            @Override
            public Class[] getAllLoadedClasses() {
                return new Class[0];
            }

            @Override
            public Class[] getInitiatedClasses(ClassLoader loader) {
                return new Class[0];
            }

            @Override
            public long getObjectSize(Object objectToSize) {
                return 0;
            }

            @Override
            public void appendToBootstrapClassLoaderSearch(JarFile jarfile) {

            }

            @Override
            public void appendToSystemClassLoaderSearch(JarFile jarfile) {

            }

            @Override
            public boolean isNativeMethodPrefixSupported() {
                return false;
            }

            @Override
            public void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) {

            }
        };

    }

}
